/*
	Copyright (c) 2009, M.P. Bartnig & A. Gosman
	
	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:
	
	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.
	
	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/
package nl.sanity.ui.helpers
{
	/**
	 * UIAlign
	 *
	 * @langversion ActionScript 3
	 *
	 * @author M.P. Bartnig
	 * @since  16/03/2009
	 */
	public class UIAlign
	{
		public static const	DEFAULT_MARGIN			:Number		= 0;
		
		public static const	ALIGN_TOP_LEFT			:String		= "alignTopLeft";
		public static const	ALIGN_TOP_MIDDLE		:String		= "alignTopMiddle";
		public static const	ALIGN_TOP_RIGHT			:String		= "alignTopRight";
		
		public static const	ALIGN_CENTER_LEFT		:String		= "alignCenterLeft";
		public static const	ALIGN_CENTER_MIDDLE		:String		= "alignCenterMiddle";
		public static const	ALIGN_CENTER_RIGHT		:String		= "alignCenterRight";
		
		public static const	ALIGN_BOTTOM_LEFT		:String		= "alignBottomLeft";
		public static const	ALIGN_BOTTOM_MIDDLE		:String		= "alignBottomMiddle";
		public static const	ALIGN_BOTTOM_RIGHT		:String		= "alignBottomRight";
		
		protected var _orientation					:String;
		protected var _marginLeft					:Number;
		protected var _marginTop					:Number;
		protected var _marginRight					:Number;
		protected var _marginBottom					:Number;
		
		/**
		 * Create a new UIAlign object
		 * 
		 * parameters are processed just like CSS.
		 * 
		 * If just one value, it's used for all.
		 * If just two, it's top/bottom, left/right.
		 * And, so on...
		 */
		public function UIAlign( top:Number = -1, right:Number = -1, bottom:Number = -1, left:Number = -1 )
		{
			if( top == -1 )
			{
				setDefaults();
				return;
			}
			else
			{
				_marginTop = _marginBottom = top;
			}
			
			if ( right == -1 )
			{
				_marginLeft = _marginRight = _marginBottom = _marginTop;
				return;
			}
			else
			{
				_marginLeft = _marginRight = right;
			}
			
			if( bottom != -1 )
			{
				_marginBottom = bottom;
			}
			
			if( left != -1 )
			{
				_marginLeft = left;
			}
		}
		
		// --- PRIVATE FUNCTIONS ----------------------------------------

		private function setDefaults():void
		{
			_marginLeft		= UIAlign.DEFAULT_MARGIN;
			_marginTop		= UIAlign.DEFAULT_MARGIN;
			_marginRight	= UIAlign.DEFAULT_MARGIN;
			_marginBottom	= UIAlign.DEFAULT_MARGIN;
			
			_orientation	= UIAlign.ALIGN_CENTER_MIDDLE;
		}
		
		
		// --- GETTER/SETTER FUNCTIONS ----------------------------------------
		
		public function set marginLeft( value:Number ):void
		{
			_marginLeft = value;
		}
		
		public function get marginLeft():Number
		{
			return _marginLeft;
		}
		
		public function set marginTop( value:Number ):void
		{
			_marginTop = value;
		}
		
		public function get marginTop():Number
		{
			return _marginTop;
		}
		
		public function set marginRight( value:Number ):void
		{
			_marginRight = value;
		}
		
		public function get marginRight():Number
		{
			return _marginRight;
		}
		
		public function set marginBottom( value:Number ):void
		{
			_marginBottom = value;
		}
		
		public function get marginBottom():Number
		{
			return _marginBottom;
		}
		
		public function set orientation( value:String ):void
		{
			_orientation = value;
		}
		
		public function get orientation():String
		{
			return _orientation;
		}
		
		public function get height():Number
		{
			return _marginTop + _marginBottom;
		}
		
		public function get width():Number
		{
			return _marginLeft + _marginRight;
		}

	}
}